package com.ourteam.product.api;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.ProductUIDomainDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIDomainBean;

public class ProductUIDomainSearchModel extends AbstractSearchModel<ProductUIDomainDAOQueryBean> {

	private String domainName;

	private String domainCode;

	private String[] status;

	public String getDomainName() {
		return domainName;
	}

	public void setDomainName(String domainName) {
		this.domainName = domainName;
	}

	public String getDomainCode() {
		return domainCode;
	}

	public void setDomainCode(String domainCode) {
		this.domainCode = domainCode;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUIDomainBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUIDomainDAOQueryBean queryBean) throws Exception {
		ProductUIDomainDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (StringUtils.isNoneBlank(domainCode)) {
			criteria.andDomainCodeLike(domainCode);
		}

		if (StringUtils.isNoneBlank(domainName)) {
			criteria.andDomainNameLike(domainName);
		}

		if (ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(status);
		}
	}

}
